package com.itasura.unitofwork;

import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

/**
 *
 * 工作单元模式：用来维护一个已经被业务事务修改（CURD操作）的业务对象列表。
 * 工作单元模式负责协调这些修改的持久化工作以及所有标记的并发问题。
 * 采用工作单元模式带来的好处是能够保证数据的完整性
 *
 * @author sailor wang
 * @date 2018/10/15 下午2:52
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Map<String, List<Student>> context = Maps.newHashMap();
        StudentDatabase studentDatabase = new StudentDatabase();

        StudentRepository repository = new StudentRepository(context,studentDatabase);

        Student zhangsan = new Student(1,"zhang san","世纪公园");

        Student lisi = new Student(2,"li si","滨江大道");

        Student wangwu = new Student(3,"wang wu","陆家嘴");

        repository.registerNew(zhangsan);

        repository.registerModify(lisi);

        repository.registerDelete(wangwu);

        repository.commit();
    }
}